package com.twu.biblioteca.app.user;

public class User implements Comparable<User> {
    private final String LINE_SEPARATOR = System.getProperty("line.separator");

    private String libraryNumber;
    private String password;
    private String name;
    private String emailAddress;
    private String phoneNumber;

    public User(String libraryNumber, String password, String name, String emailAddress, String phoneNumber) {
        this.libraryNumber = libraryNumber;
        this.password = password;
        this.name = name;
        this.emailAddress = emailAddress;
        this.phoneNumber = phoneNumber;
    }

    public String getLibraryNumber() {
        return libraryNumber;
    }

    public String getPassword() {
        return password;
    }

    @Override
    public int compareTo(User other){
        int libraryNumber = this.libraryNumber.compareTo(other.libraryNumber);
        if (libraryNumber != 0) {return libraryNumber;}

        int password = this.password.compareTo(other.password);
        if (password != 0) {return password;}

        return this.name.compareTo(other.name);
    }

    @Override
    public boolean equals(Object otherObj) {
        if (otherObj == null) {
            return false;
        }
        if (getClass() != otherObj.getClass()) {
            return false;
        }

        User otherUser  = (User) otherObj;
        if (this.libraryNumber != otherUser.libraryNumber) {
            return false;
        }
        if (this.password != otherUser.password) {
            return false;
        }

        return this.name == otherUser.name;
    }

    public String getName() {
        return name;
    }

    public String getUserDetails() {
        return "Name: " + this.name + LINE_SEPARATOR + "Email: " + this.emailAddress + LINE_SEPARATOR +
                "Phone Number: " + this.phoneNumber + LINE_SEPARATOR;
    }
}
